//
// Created by miaomiaole on 2024/1/7.
//

#include "src_imgs.h"

void show_imgs() {
    auto img = imread("C:\\Users\\tom12\\Desktop\\download.png", 0);
    imshow("test", img);
    waitKey(2000);
}

void create_imgs() {
    Mat color1(640, 480, CV_8UC3, Scalar(244, 233, 222));

    imshow("color1", color1);

    auto eye_imgs = Mat::eye(300, 300, CV_8UC1);

    imshow("eye_imgs", eye_imgs);
    waitKey(0);
}

void read_video() {
    system("color F0");
    VideoCapture video("ff4fdfb38ce629991d1b850ab1a6a38f.mp4");

    if (video.isOpened()) {
        cout << "width：" << video.get(CAP_PROP_FRAME_WIDTH) << endl;
        cout << "height：" << video.get(CAP_PROP_FRAME_HEIGHT) << endl;
        cout << "fps：" << video.get(CAP_PROP_FPS) << endl;
        cout << "count FRAME：" << video.get(CAP_PROP_FRAME_COUNT) << endl;
    } else {
        cout << "no find video" << endl;
    }
    while (true) {
        Mat frame;
        video >> frame;
        if (frame.empty()) {
            break;
        }
        imshow("video mat", frame);
        waitKey(1000 / video.get(CAP_PROP_FPS));
    }

    waitKey();

}

void cv_color_imgs() {
    auto imgs = imread("C:\\Users\\tom12\\Pictures\\MVIMG_20230225_160947.jpg");


    Mat gray, Hsv, Yuv, Lab, img32;
    imgs.convertTo(img32, CV_32F, 1.0 / 255);
    cvtColor(img32, Hsv, COLOR_BGR2HSV);
    cvtColor(img32, Yuv, COLOR_BGR2YUV);
    cvtColor(img32, Lab, COLOR_BGR2Lab);
    cvtColor(img32, gray, COLOR_BGR2GRAY);
    imshow("source", imgs);
    imshow("img32", img32);
    imshow("Hsv", Hsv);
    imshow("Yuv", Yuv);
    imshow("Lab", Lab);
    imshow("gray", gray);

}

void split_imgs() {
    auto img_cat = imread("C:\\Users\\tom12\\Pictures\\20220116173054.jpg");
    Mat Hsv;
    cvtColor(img_cat, Hsv, COLOR_RGB2HSV);
    imshow("img_cat", img_cat);
    imshow("Hsv", Hsv);

    Mat imgv0, imgv1, imgv2;
    Mat imgs0, imgs1, imgs2;
    Mat result0, result1, result2;

    // 图片颜色拆分
    Mat imgs[3];
    split(img_cat, imgs);

    imshow("B color:", imgs[0]);
    imshow("G color:", imgs[1]);
    imshow("R color:", imgs[2]);

    // 合并
    merge(imgs, 3, result0);

    imshow("result0 ", result0);


    vector<Mat> imgv;
    split(Hsv, imgv);

    imshow("H:",imgv.at(0));
    imshow("S:",imgv.at(1));
    imshow("V:",imgv.at(2));

    imgv.push_back(imgv.at(1));
    merge(imgv,result1);

    imshow("result1:",result1);

}
